from Utility import Clipboard, MD5Extract
import VDownload
from Base import Singleton


class Watcher(Singleton.Singleton, Clipboard.ClipboardObserver):
    def __init__(self):
        self.clipboard_watcher = Clipboard.ClipboardWatcher.Instance()
        self.downloader = VDownload.VDownloader.Instance()
        self.extracter = MD5Extract.MD5Extracter(self)
        self.__MonClipboard()


    def Start(self):
        self.downloader.Start()
        
    def __MonClipboard(self):
        self.clipboard_watcher.AddObserver(self)
        
        
    def OnClipboardChange(self, data):
        self.extracter.Extract(data)

    def OnMD5Found(self, md5):
        self.downloader.Download(md5.toAscii().data())
        
    




#+--------------------------Test---------------------------+#   
    
if __name__ == '__main__':
    watcher = Watcher.Instance()
    watcher.Start()
    
    
    

